package cn.lwj.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import kotlin.time.MeasureTimeKt;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.UUID;

@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 执行插入操作时调用该方法
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
//        metaObject 代表的就是对应操作的实体类对象
//        category.setCreateTime(LocalDateTime.now());
//        category.setUpdateTime(LocalDateTime.now());
//
//        category.setCreateUser((Long) request.getSession().getAttribute("employee"));
//        category.setUpdateUser((Long) request.getSession().getAttribute("employee"));
        log.info("添加前");
        log.info(metaObject.toString());
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());

        metaObject.setValue("createUser",BaseContext.getCurrentId());
        metaObject.setValue("updateUser",BaseContext.getCurrentId());
        log.info("添加后");
        log.info(metaObject.toString());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser",BaseContext.getCurrentId());
    }
}
